package com.example.securitydemo.api;

import com.aaa.entity.TabMenu;
import com.aaa.entity.TabRole;
import com.aaa.entity.TabUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.securitydemo.mapper.TabMenuMapper;
import com.example.securitydemo.mapper.TabRoleMapper;
import com.example.securitydemo.mapper.TabUserMapper;
import com.example.securitydemo.service.ITabUserService;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("userApi")
public class UserApiController {

    @Resource
private TabUserMapper userMapper;

    @Resource
    private TabRoleMapper roleMapper;

    @Resource
    private TabMenuMapper menuMapper;
    /**
     * 根据用户的名字查询用户的信息
     * @return
     */
    @PostMapping("name/{name}")
    public TabUser getUserByName(@PathVariable String name) {
        //
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("username",name);// username="1222"
        TabUser one = userMapper.selectOne(queryWrapper);
        return one;

    }
    /**
     * 根据用户的id  查询用户的角色信息
     */
    @PostMapping("{uid}")
    public List<TabRole> getByUid(@PathVariable Integer uid){
        // 调用
        List<TabRole> roleList = roleMapper.getRoleByUid(uid);
        return roleList;
    }

    /**
     * 根据用户的id 查询用户的资源的信息
     */
    @PostMapping("menus/{rids}")
    public  List<TabMenu> getMenusByUid(@PathVariable List<Integer> rids){
        List<TabMenu> menuList = menuMapper.getMenusByRids(rids);
        return menuList;
    }
}
